package com.yunyike.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.ShopperMapper;
import com.yunyike.model.Shopper;
import com.yunyike.service.IShopperService;

@Service("shopperServiceImpl")
public class ShopperServiceImpl implements IShopperService{

	private static Logger log = LoggerFactory.getLogger(ShopperServiceImpl.class);

	@Autowired
	private ShopperMapper shopperMapper;

	public int addShopper(Shopper shopper) {
		
		int result;
		try {
			result = shopperMapper.insertSelective(shopper);
		} catch (Exception e) {
			log.error("addShopper has error.message:"+e.getMessage(),e);
			return 0;
		}
		return result;
	}

	/**
	 * 获取售货员信息
	 */
	public Shopper findShopperById(String shopperId) {
		Shopper shopper;
		try {
			shopper = shopperMapper.selectByPrimaryKey(shopperId);
		} catch (Exception e) {
			log.error("findShopperById has error.message:"+e.getMessage(),e);
			return null;
		}
		return shopper;
	}

	/**
	 * 根据店铺 获取导购列表
	 */
	public List<Shopper> findShopperByShop(String shopId) {
		
		List<Shopper> shoppers;
		try {
			shoppers = shopperMapper.selectShoppersByShopId(shopId);
		} catch (Exception e) {
			log.error("findShopperByShop has error,message:"+e.getMessage(),e);
			return null;
		}
		
		return shoppers;
	}
	

}
